import 'package:flutter/material.dart';

class TodoListBox extends StatelessWidget {
  TodoListBox({
    Key key,
    @required this.title,
    @required this.itemBuilder,
    this.itemCount = 0,
    this.color = Colors.white,
    this.titleColor = Colors.black,
    this.maxHeight,
    this.minHeight,
  }) : super(key: key);

  final Widget title;
  final Color color;
  final Color titleColor;
  final int itemCount;
  final IndexedWidgetBuilder itemBuilder;
  final double minHeight, maxHeight;

  @override
  Widget build(BuildContext context) {
    var widgets = <Widget>[];
    for (var i = 0; i < itemCount; i++) {
      widgets.add(itemBuilder(context, i));
    }
    return Stack(
      children: <Widget>[
        Card(
          elevation: 5,
          margin: EdgeInsets.only(top: 10),
          shape: const RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(8.0)),
          ),
          child: ConstrainedBox(
            constraints: BoxConstraints(
              minWidth: MediaQuery.of(context).size.width,
              minHeight: minHeight ?? 0,
              maxHeight: maxHeight ?? double.infinity,
            ),
            child: Padding(
              padding: EdgeInsets.fromLTRB(10, 20, 10, 10),
              child: SingleChildScrollView(
                child: Column(
                  children: widgets,
                ),
              ),
            ),
          ),
        ),
        Card(
          elevation: 0,
          color: titleColor,
          margin: EdgeInsets.only(left: 15),
          child: Padding(
            padding: EdgeInsets.fromLTRB(10, 5, 10, 5),
            child: title,
          ),
        ),
      ],
    );
  }
}
